/*!
  @file validity_checker.h
  @copyright 2013 Kubota Lab. All rights resereved.
*/

#ifndef _VALIDITY_CHECKER_H_
#define _VALIDITY_CHECKER_H_

#include <iterator>

#include "mrover_vo/feature.h"

namespace vo {

/*! 
 *  @brief  Validity checker base class
 *  @author Kyohei Otsu <kyon@ac.jaxa.jp>
 *  @date   2013
 *  
 *  detailed documentaiton for this class
 */

template <typename Parent, typename PointType>
class ValidityChecker {
 public:
  // typedef boost::shared_ptr<ValidityChecker> Ptr;
  typedef boost::shared_ptr<ValidityChecker const> ConstPtr;

  ValidityChecker() { }

  ~ValidityChecker() { }

  //! should be called by the clients
  void checkForValidityWithErase(Parent *parent) const {
    Feature::Matches::iterator match_it = parent->matches_->begin();
    while (match_it != parent->matches_->end()) {
      const PointType &input_pt  = parent->input_kp_->at(match_it->queryIdx).pt;
      const PointType &target_pt = parent->target_kp_->at(match_it->trainIdx).pt;
      if (!isValid(input_pt, target_pt)) {
        match_it = parent->matches_->erase(match_it);
      } else {
        ++match_it;
      }
    }
  }

 protected:
  //! Returns valid or invalid. should be overrided by inherited class
  virtual bool isValid(const PointType &input, const PointType &target) const = 0;

};

}  // namespace vo

#endif
